/* Let there be N prayers (numbered 1..N) and M slots on the wheel. Initially,
 * each prayer is assigned an identity room number, i.e (1, 2, ..., N).
 *
 * After each round, they permute their room numbers according to the 
 * permutation designated on the wheel. There are M such permutations.
 * We denote them as S[1], S[2], ..., S[M].
 *
 * After x times of applying the permutation, they return to their identity
 * room assignment. Let x = M*L + K where 1 <= K <= M. The total permutation
 * is
 *     (s[1]*...*s[M] )^L * (s[1]*...*s[K]) = Identity.
 * Therefore the task is to find the smallest x that solves this equation.
 * 
 * Let R = s[1]*...*s[M] be the total permutation of a wheel. For each K, 
 * we have R^L = (s[1]*...*s[K])^(-1). The right-hand side is given. For the
 * left-hand side, we can decompose R into a product of cycles, e.g.:
 *    R = (1 3 6) (2 4) (5).
 * For each element i, the condition that it moves to the desired position, j
 * is
 *    distance(i to j) = L mod cycle-length.
 * This gives us N congruence equations, which can be solved by the Chinese
 * remainder theorem.
 */

#include <stdio.h>
#include <memory.h>

#define MAX_N   200
#define MAX_M   200

typedef int Permutation[MAX_N];

static int N;   /* size of each permutation */
static int M;   /* number of permutatations */
static Permutation S[MAX_M];    /* S[i], i=0..M-1 */

static void SetIdentityPermutation(Permutation dst)
{
    int i;
    for (i = 0; i < N; i++)
        dst[i] = i;
}

static void CopyPermutation(Permutation dst, const Permutation src)
{
    int i;
    for (i = 0; i < N; i++)
        dst[i] = src[i];
}

static void InvertPermutation(Permutation dst, const Permutation src)
{
    int i;
    for (i = 0; i < N; i++)
        dst[src[i]] = i;
}

static void CompoundPermutation(Permutation first, const Permutation second)
{
    int i;
    for (i = 0; i < N; i++)
        first[i] = second[first[i]];
}

/* Solves the equation ax + by = gcd(a,b). Returns gcd(a,b).*/
static int egcd(int a, int b, int *px, int *py)
{
    int r, r_2 = a, r_1 = b;
    int x_2 = 1, x_1 = 0;
    int y_2 = 0, y_1 = 1;
    if (a == 0 || b == 0)
        return 0;
    while (r = r_2 % r_1)
    {
        int q = r_2 / r_1;
        int x = x_2 - q*x_1;
        int y = y_2 - q*y_1;
        x_2 = x_1; x_1 = x;
        y_2 = y_1; y_1 = y;
        r_2 = r_1; r_1 = r;
    }
    *px = x_1;
    *py = y_1;
    return r_1;
}

/* Finds a family of solutions x = x0 + k*m to the congruence equation
 *     x == a1 (mod m1) and x == a2 (mod m2). 
 * Here 0 <= x0 < m. Returns non-zero if successful, or 0 if no solution.
 */
static int SolveCongruence2(
    int a1, int m1, int a2, int m2,
    long long *px, long long *pm)
{
    int p, q;
    int g = egcd(m1, m2, &p, &q);
    int d = a2 - a1;
    long long m, x, k;

    if (g != 1)
    {
        if (d % g != 0)
            return 0;
        m1 /= g;
        m2 /= g;
        d /= g;
    }
    k = (long long)d * p % m2;
    m = (long long)m1 * m2 * g;
    x = (k * m1 * g + a1) % m;
    if (x < 0)
        x += m;
    *px = x;
    *pm = m;
    return 1;
}

/* Find the smallest non-negative integer x that solves the congruence system
 *   x == a[0] (mod m[0])
 *   x == a[1] (mod m[1])
 *   ...
 *   x == a[N-1] (mod m[N-1])
 * If a solution cannot be found or would be greater than 'threshold', 
 * returns -1. Otherwise, returns x.
 */
static int SolveCongruenceSystem(const int m[], const int a[], int threshold)
{
    int mm = m[0], aa = a[0], i;
    for (i = 1; i < N; i++)
    {
        /* Solves x == aa (mod mm) and x == a[i] (mod m[i]). */
        if (mm == -1) /* modulus exceeds threshold */
        {
            if (aa % m[i] != a[i]) /* solution would exceed threshold */
                return -1;
        }
        else
        {
            long long x, newm;
            if (!SolveCongruence2(aa, mm, a[i], m[i], &x, &newm))
                return -1;
            mm = (newm > threshold)? -1 : (int)newm;
            if (x > threshold)
                return -1;
            aa = (int)x;
        }
    }
    return aa;
}

int solve()
{
    Permutation R, T;
    int i, k;
    int distance[MAX_N][MAX_N]; /* d[i][j] = minimum L such that R^L(i) = j */
    int cycle[MAX_N];           /* cycle length of each element in R */
    int best = 0;

    /* Compute the compound permutation of a full rotation of the wheel. */
    SetIdentityPermutation(R);
    for (k = 0; k < M; k++)
        CompoundPermutation(R, S[k]);

    /* Compute the distance and cycle length of each element under R. */
    for (i = 0; i < N; i++)
    {
        int j = i, d = 0;
        memset(distance[i], -1, sizeof(int)*N);
        do 
        {
            distance[i][j] = d++;
        } while ((j = R[j]) != i);
        cycle[i] = d;
    }

    /* Compound S[k] one by one. For each k, try solve the equation by 
     * inverting S[k] and left-multiplying it to the right-hand side T.
     * Repeat until we find a solution.
     */
    SetIdentityPermutation(T);
    for (k = 0; k < M; k++)
    {
        Permutation inv;
        int a[MAX_N]; /* congruence system L == a[i] (mod cycle[i]) */
        int L; 

        /* Update T = inv(S[k]) * T. */
        InvertPermutation(inv, S[k]);
        CompoundPermutation(inv, T);
        CopyPermutation(T, inv);

        /* Build a congruence system to solve R^L = T. */
        for (i = 0; i < N; i++)
        {
            if (distance[i][T[i]] < 0) /* unreachable */
                break;
            a[i] = distance[i][T[i]];
        }
        if (i < N) /* unreachable */
            continue;

        /* Try solve the congruence system L == a[i] (mod cycle[i]). */
        L = SolveCongruenceSystem(cycle, a, (1000000000 - k - 1) / M);
        if (L >= 0)
        {
            int years = L * M + k + 1;
            if (best == 0 || years < best)
                best = years;
        }
    }

    /* No solution found... return 0. */
    return best;
}

int main()
{
    while (scanf("%d %d", &N, &M) == 2)
    {
        int i, j, years;
        for (j = 0; j < N; j++)
        {
            for (i = 0; i < M; i++)
            {
                scanf("%d", &S[i][j]);
                --S[i][j]; /* one based -> zero based */
            }
        }   
        years = solve();
        if (years == 0)
            printf("No one knows.\n");
        else
            printf("%d\n", years);
    }
    return 0;
}
